<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>公司列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${hostUrl}/static/layui/css/layui.css"  media="all">
    <script src="${hostUrl}/static/layui/layui.js"></script>
    <script src="${hostUrl}/static/layui/custom/js/dickov.js"></script>
    <script>
        layui.use(['laypage', 'layer', 'table','jquery'], function(){
            // 使用弹出层
            var layer = layui.layer;
            // 使用table
            var table = layui.table;
            var $ = layui.jquery;

            table.render({
                elem: '#companyTable'
                ,skin:'row line'
                ,even:true
                ,title:"公司列表"
                ,toolbar: '#headToolBar'
                ,defaultToolBar:true
                ,height: 312
                ,url: '${hostUrl}/company/getList' //数据接口
                ,page: true //开启分页
                ,limit: 10 // 每页的数量
                ,limits:[10,20,50]
                ,cols: [[ //表头
                    {field: 'companyId', title: '公司ID', width:120, sort: true, fixed: 'left'}
                    ,{field: 'companyName', title: '公司名', width:140}
                    ,{field: 'companyAddress', title: '地址',width:200}
                    ,{toolbar: '#barDemo', width: 165, align:'center',fixed: 'right' }
                ]]
            });

            //监听行工具事件
            table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"

                var layEvent = obj.event; //获得 lay-event 对应的值
                var data = obj.data; //获得当前行数据
                var company = obj.data;

                if(layEvent === 'detail'){
                    layer.msg('查看操作');
                } else if(layEvent === 'del'){
                    layer.confirm('真的删除['+company.companyName+']公司吗？', function(index){
                        obj.del(); //删除对应行（tr）的DOM结构
                        layer.close(index);
                        //向服务端发送删除指令
                    });
                } else if(layEvent === 'edit'){
                    console.log( company.companyId);
                    layer.msg('即将对【'+company.companyName+'】公司进行编辑操作。');
                }
            });

            $("#addCompany").click(function(){
                layer.msg("添加公司");
            });

        });
    </script>
</head>

<body>

<script type="text/html" id="headToolBar">
    <a class="layui-btn layui-btn-primary layui-btn-sm" id="addCompany">
        <i class="layui-icon layui-icon-add-1"></i>
    </a>
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<table id="companyTable" lay-filter="test"></table>
</body>

</html>